package com.jacquesh;

import com.jacquesh.partition.CustomPartitioner;
import org.apache.flink.api.java.functions.KeySelector;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class FlinkDemo0017 {
    public static void main(String[] args) throws Exception {

            StreamExecutionEnvironment environment =
                    StreamExecutionEnvironment.getExecutionEnvironment();
            /**设置默认并行度为4*/
            environment.setParallelism(4);
            /**获取随机数流 ： 1~4*/
            DataStreamSource<Long> stream = environment
                    .generateSequence(1,4)
                    /**并行度设置为2*/
                    .setParallelism(2);
            stream
                   .partitionCustom(new CustomPartitioner(),
                     (KeySelector<Long, Long>) aLong -> aLong)
                    .print()
                    .setParallelism(2);
            environment.execute("custom partition");
        }
    }

